package com.shs.com.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shs.com.entity.User;
import com.shs.com.mapper.UserMapper;
import com.shs.com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    //查询用户列表
    @Override
    public Map<String, Object> queryUserList(Map<String, Object> map) {
        PageHelper.startPage(Integer.parseInt(map.get("pageNum").toString()), Integer.parseInt(map.get("pageSize").toString()));
        List<User> list = userMapper.queryUserList(map);
        PageInfo<User> pageInfo = new PageInfo<>(list);
        //获取总记录数
        long total = pageInfo.getTotal();
        //获取总页数据
        List<User> pageInfoList = pageInfo.getList();
//        把查询结果放到一个Map
        HashMap<String, Object> resultMap = new HashMap<>();
        resultMap.put("total", total);
        resultMap.put("rows", pageInfoList);
        return resultMap;
    }

    @Override
    public User queryUser(Map<String, Object> map) {
        return userMapper.queryUser(map);
    }

    @Override
    public void addUser(Map<String, Object> map) {
        userMapper.addUser(map);
    }

    //修改用户
    @Override
    public void updateUser(Map<String, Object> map) {
        userMapper.updateUser(map);
    }

    @Override
    public void updateUserById(Map<String, Object> map) {
        userMapper.updateUserById(map);
    }

    //删除用户根据用户名
    @Override
    public void delUser(Map<String, Object> map) {
        userMapper.delUser(map);
    }

    @Override
    public void updateUserPass(Map<String, Object> map) {
        userMapper.updateUserPass(map);
    }


}
